package cc.yugu.yhdw.webserver.web.controller.security.basic;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.basic.MobileMessageTemplate;
import cc.yugu.yhdw.common.domain.basic.User;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.constant.AppConstEnum;
import cc.yugu.yhdw.webserver.service.basic.MobileMessageTemplateService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
/**
 * 短信模板控制器
 * 
 * @Date:Created in 2018/7/24 9:07
 * @Author:
 * @Modified By: zjn 2018/7/24 9:07
 */ 
@Controller
@RequestMapping(value = "/security/basic/mobile_message_template")
public class MobileMessageTemplateController extends SecurityController {

    @Autowired
    MobileMessageTemplateService mobileMessageTemplateService;

    @RequestMapping(value = "index.htm")
    public void index(Model model) {
        model.addAttribute(MENU_CODE_NAME, AppConstEnum.Menu.MENU_05_02.getValue());
    }
    /**
    * 分页查询
    * 
    * @Param: [search, request]
    * @Return: cc.yugu.yhdw.common.entity.json.PageResult
    * @Author By: zjn 2018/7/24  9:07
    */ 
    @RequestMapping("page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(MobileMessageTemplate search,HttpServletRequest request) {
        if (getSessionUser(request).getType() == User.Type.AGENT.getValue()||getSessionUser(request).getType() == User.Type.AGENCY.getValue()) {
            search.setAgentId(getSessionUser(request).getAgentId());
        }
        return PageResult.successResult(mobileMessageTemplateService.findPage(search));
    }
    /**
    * 页面点击修改，弹出修改页面
    * 
    * @Param: [agentId, id, model]
    * @Return: java.lang.String
    * @Author By: zjn 2018/7/24  9:08
    */ 
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping("edit.htm")
    public String edit(int agentId, int id, Model model) {
        // 查询短信模板
        MobileMessageTemplate entity = mobileMessageTemplateService.find(agentId, id);
        if(entity == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        }
        model.addAttribute("entity", entity);
        return "/security/basic/mobile_message_template/edit";
    }
    /**
    * 更新
    *
    * @Param: [entity]
    * @Return: cc.yugu.yhdw.common.entity.json.ExtResult
    * @Author By: zjn 2018/7/24  9:10
    */
    @ViewModel(ViewModel.JSON)
    @RequestMapping("update.htm")
    @ResponseBody
    public ExtResult update(MobileMessageTemplate entity) {
        return mobileMessageTemplateService.update(entity);
    }
    /**
    * 页面点击查看，弹出查看页面
    *
    * @Param: [agentId, id, model]
    * @Return: java.lang.String
    * @Author By: zjn 2018/7/24  9:10
    */
    @ViewModel(ViewModel.INNER_PAGE)
    @RequestMapping("view.htm")
    public String view(int agentId, int id, Model model) {
        MobileMessageTemplate entity = mobileMessageTemplateService.find(agentId, id);
        if(entity == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        }
        model.addAttribute("entity", entity);
        return "/security/basic/mobile_message_template/view";
    }

}
